<%@ page import="ro.gateway.aida.locations.EditLocationForm,
                 ro.gateway.aida.locations.LocationEditorForm"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>
<%
      EditLocationForm form = ( EditLocationForm ) session.getAttribute("editlocationform");
      LocationEditorForm main_form = ( LocationEditorForm ) session.getAttribute("loceditorform");
%>
<%
 String ctx = request.getContextPath();
%>

<head>
     <LINK rel="stylesheet" type="text/css" href="<html:rewrite page='/alf.css'/>">
<trans:initPage module="browseloc" />
<html:html>
      <script language="javascript">
            function send_message(form, name, value) {
                  form.elements[name].value = value;
                  form.submit();
            }
            function submitez(forma) {
			var lat = 0;
			if (forma.latitude.value) {
			  lat = parseFloat(forma.latitude.value);
			}
			var longit = 0;
			if (forma.longitude.value) {
			longit = parseFloat(forma.longitude.value);
			}
			if (!lat && (lat!=0)) {
			    alert('Wrong latitude');
			    return;
			}
			if (!longit && (longit!=0)) {
			    alert('Wrong longitude');
			    return;
			}
			if (!forma.name.value) {
			    alert('Wrong name');
			    return;
			}
			<% if ("update".equals(form.action)) { %>
				if (!forma.id) {
					alert('Unauthorized access (location editor)');
					return;
				}
			<% } %>
			forma.submit();
            }
      </script>
      <style>
            a.abut {
                  text-decoration:none;
                  color: black;
                  font-weight:normal;
            }
      </style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<jsp:include page="../header.jsp" />
      <html:form action="/location/edit_location">
      <html:hidden property="action" value="<%=form.action%>" />
      <html:hidden property="otype" value="<%=form.otype%>" />
      <html:hidden property="id" /> 
      <table width="90%" border="0" align="center" cellpadding="5" cellspacing="1" background=<%=ctx%>/images/pixelbgtable.gif class="text_searchbold" style="margin-top:20px;border:1px solid #CCCCCC;">
            <tr>
                  
    <td colspan="2"> <div align="center"><font color="#FFFFFF"><trans:showPageMessage label="editloc:locationmanager" /></font></div></td>
            </tr>
            <tr bgcolor="#FFFFFF">
                  <td width="40%" align="right"><trans:showPageMessage label="editloc:name" />:</td>
                  <td width="60%">

                    <input type="text" name="name" value="<%=form.name != null ? form.name : ""%>" onkeydown="textCounter(this.form.name,this.form.cname,200);" onkeyup="textCounter(this.form.name,this.form.cname,200);"/>
                    <input readonly type="text" name="cname" size="3" maxlength="4" value="">
                    <trans:showPageMessage label="charactersleft" />
                  </td>
            </tr>
            <% if ("town".equals(form.getOtype())) { %>
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:type" />:</td>
                  <td>
                  <select name="type">
                        <option value="-1"><trans:showPageMessage label="editloc:na" hide_link="true" /></option>
                        <option <%=form.type == 1 ? "selected=\"true\"" : ""%>value="1"><trans:showPageMessage label="editloc:municipality" hide_link="true" /></option>
                        <option <%=form.type == 2 ? "selected=\"true\"" : ""%>value="2"><trans:showPageMessage label="editloc:city" hide_link="true" /></option>
                        <option <%=form.type == 3 ? "selected=\"true\"" : ""%>value="3"><trans:showPageMessage label="editloc:town" hide_link="true" /></option>
                  </select>
                  </td>
            </tr>
            <% } %>
            <% if ("country".equals(form.getOtype()) && "create".equals(form.action)) { %>
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:ISOcode" /> <font color="red">*</font>:</td>
                  <td>
                  <input type="text" size="3" name="iso3" value="<%=form.id != null ? form.id : ""%>" onkeydown="textCounter(this.form.id,this.form.cid,3);" onkeyup="textCounter(this.form.id,this.form.cid,3);"/>
                  </td>
            </tr>
            <% } %>
            <% if ("cregion".equals(form.getOtype())) { %>
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:code" />:</td>
                  <td>
                  <input type="text" size="3" name="cregion_code" value="<%=form.id != null ? form.id : ""%>" onkeydown="textCounter(this.form.cregion_code,this.form.ccregion_code,3);" onkeyup="textCounter(this.form.cregion_code,this.form.ccregion_code,3);"/>
                  </td>
            </tr>
            <logic:present name="cregions">
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:parentregion" />:</td>
                  <td>
                  <html:select property="cregion_parent_id">
                    <html:option value="-1"><trans:showPageMessage label="browseloc.nocregion" hide_link="true"/></html:option>
                    <html:options collection="cregions" property="id" labelProperty="name"/>
                  </html:select>
                  </td>
            </tr>
            </logic:present>
            <% } %>
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:geocode" />:</td>
                  <td><input type="text" name="geo_code" value="<%=form.geo_code != null ? form.geo_code : ""%>" onkeydown="textCounter(this.form.geo_code,this.form.cgeo_code,30);" onkeyup="textCounter(this.form.geo_code,this.form.cgeo_code,30);"/></td>
            </tr>
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:lattitude" />:</td>
                  <td><input type="text" name="latitude" value="<%=form.latitude%>" onkeydown="textCounter(this.form.latitude,this.form.clatitude,30);" onkeyup="textCounter(this.form.latitude,this.form.clatitude,30);"/></td>
            </tr>
            <tr bgcolor="#FFFFFF">
                  <td align="right"><trans:showPageMessage label="editloc:longitude" />:</td>
                  <td><input type="text" name="longitude" value="<%=form.longitude%>" onkeydown="textCounter(this.form.longitude,this.form.clongitude,30);" onkeyup="textCounter(this.form.longitude,this.form.clongitude,30);"/></td>
            </tr>
            <tr bgcolor="#FFFFFF">
                  <td colspan="2" align="center">
                  <input class="butonsave" type="button" name="unknown01" value="<trans:showPageMessage label="editloc:Save" hide_link="true" />"
                        onClick="javascript:submitez(this.form);"/>
                  <input class="butonsave" type="button" value="<trans:showPageMessage label="editloc:cancel" hide_link="true" />"
                        onClick="javascript:window.location='editor.do?<%=main_form.getParametersForEditor()%>';"
                        />
                  </td>
            </tr>
      </table><trans:showPageMessage label="translator.showhiddentags"/>
<script type="text/javascript" src="<html:rewrite page='/javascript/textCounter.js'/>"></script>
      </html:form>
	  <jsp:include page="../footer.jsp" />
</html:html>